using System;
using System.Threading;
using FwkLight.CodeExtensions;

namespace FwkLight.Web
{
  public class ThreadItemDictionary : IItemDictionary
  {
    public void Add<ItemToPutIn> ( IItemKey<ItemToPutIn> key, ItemToPutIn item )
    {
      if (Contains(key))
        return;
      Thread.SetData(Thread.GetNamedDataSlot(key.Key), item);
    }

    public Item Get<Item> ( IItemKey<Item> key )
    {
      object data = Thread.GetData(Thread.GetNamedDataSlot(key.Key));
      if (data == null)
        return default(Item);

      return (Item)data;
    }

    public bool Contains<Item> ( IItemKey<Item> key )
    {
      object data = Thread.GetData(Thread.GetNamedDataSlot(key.Key));
      return data != null;
    }

    public void Remove<ItemToPutIn> ( IItemKey<ItemToPutIn> key )
    {
      throw new NotImplementedException();
    }
  }
}